home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / PC Card Manager / CIncludes / Synchronization.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-13  |  6.3 KB  |  218 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        Synchronization.h
  3.  
  4.      Contains:    Synchronization Interfaces
  5.  
  6.      Version:    System 8
  7.  
  8.      DRI:        Bill Kincaid
  9.  
  10.      Copyright:    © 1984-1996 by Apple Computer, Inc.
  11.                  All rights reserved.
  12.  
  13.      Warning:    *** APPLE INTERNAL USE ONLY ***
  14.                  This file may contain unreleased API's
  15.  
  16.      BuildInfo:    Built by:            SuperMario Build Daemon
  17.                  With Interfacer:    2.0d11   (PowerPC native)
  18.                  From:                Synchronization.i
  19.                      Revision:        18
  20.                      Dated:            3/5/96
  21.                      Last change by:    WSK
  22.                      Last comment:    Add CountingSemaphores.
  23.  
  24.      Bugs:        Report bugs to Radar component “System Interfaces”, “Latest”
  25.                  List the version information (from above) in the Problem Description.
  26.  
  27. */
  28. #ifndef __SYNCHRONIZATION__
  29. #define __SYNCHRONIZATION__
  30.  
  31. #ifndef __TYPES__
  32. #include <Types.h>
  33. #endif
  34. #ifndef __KERNEL__
  35. #include <Kernel.h>
  36. #endif
  37.  
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41.  
  42. #if PRAGMA_IMPORT_SUPPORTED
  43. #pragma import on
  44. #endif
  45.  
  46. #if PRAGMA_ALIGN_SUPPORTED
  47. #pragma options align=power
  48. /* the following contents can only be used by compilers that support PowerPC struct alignment */
  49.  
  50. #if FOR_SYSTEM8_PREEMPTIVE
  51. /* Note:  Lock, ReadWriteLock, and CountingSemaphore data structures must be LONG WORD ALIGNED in memory!*/
  52. struct Lock {
  53.     UInt32                             theInfo[2];
  54. };
  55. typedef struct Lock Lock;
  56.  
  57. typedef Lock *LockPtr;
  58. struct ReadWriteLock {
  59.     UInt32                             theInfo[5];
  60. };
  61. typedef struct ReadWriteLock ReadWriteLock;
  62.  
  63. typedef ReadWriteLock *ReadWriteLockPtr;
  64. struct CountingSemaphore {
  65.     UInt32                             theInfo[6];
  66. };
  67. typedef struct CountingSemaphore CountingSemaphore;
  68.  
  69. typedef CountingSemaphore *CountingSemaphorePtr;
  70. typedef OptionBits LockOptions;
  71.  
  72. enum {
  73.     kLockDisablesSwis            = 0x00000001,                    /* disable software interrupts while locked*/
  74.     kLockAdjustsPriorities        = 0x00000002,                    /* lock prevents priority inversion*/
  75.     kLockDisablesCompletionRoutines = 0x00000004                /* disable software interrupts and system 7 completion routines while locked*/
  76. };
  77.  
  78. typedef void *InterruptState;
  79. /*
  80.  Simple lock routines
  81.  Locks may be created with the kLockDisablesSwis and/or kLockDisablesCompletionRoutines options,
  82.  but no others.
  83. */
  84. extern OSStatus CreateLock(Lock *theLock, LockOptions theOptions);
  85.  
  86. extern OSStatus DeleteLock(Lock *theLock);
  87.  
  88. extern OSStatus BeginLockedSection(Lock *theLock);
  89.  
  90. extern OSStatus TryBeginLockedSection(Lock *theLock);
  91.  
  92. extern OSStatus EndLockedSection(Lock *theLock);
  93.  
  94. extern Boolean IsLockedSectionHeld(Lock *theLock);
  95.  
  96. /*
  97.  Reader/writer lock routines
  98.  ReadWriteLocks may be created with the kLockDisablesSwis, kLockDisablesCompletionRoutines,
  99.  and/or kLockAdjustsPriorities options.
  100. */
  101. extern OSStatus CreateReadWriteLock(ReadWriteLock *theReadWriteLock, LockOptions theOptions);
  102.  
  103. extern OSStatus DeleteReadWriteLock(ReadWriteLock *theReadWriteLock);
  104.  
  105. extern OSStatus BeginReadLockedSection(ReadWriteLock *theReadWriteLock);
  106.  
  107. extern OSStatus TryBeginReadLockedSection(ReadWriteLock *theReadWriteLock);
  108.  
  109. extern OSStatus EndReadLockedSection(ReadWriteLock *theReadWriteLock);
  110.  
  111. extern OSStatus BeginWriteLockedSection(ReadWriteLock *theReadWriteLock);
  112.  
  113. extern OSStatus TryBeginWriteLockedSection(ReadWriteLock *theReadWriteLock);
  114.  
  115. extern OSStatus EndWriteLockedSection(ReadWriteLock *theReadWriteLock);
  116.  
  117. extern OSStatus ChangeWriteLockToReadLock(ReadWriteLock *theReadWriteLock);
  118.  
  119. extern Boolean IsReadLockedSectionHeld(ReadWriteLock *theReadWriteLock);
  120.  
  121. extern Boolean IsWriteLockedSectionHeld(ReadWriteLock *theReadWriteLock);
  122.  
  123. extern ItemCount GetReadWriteLockReaderCount(ReadWriteLock *theReadWriteLock);
  124.  
  125. extern TaskID GetReadWriteLockWriterID(ReadWriteLock *theReadWriteLock);
  126.  
  127. /*
  128.  Counting semaphore routines
  129.  CountingSemaphores currently have no options.
  130. */
  131. extern OSStatus CreateCountingSemaphore(CountingSemaphore *theCountingSemaphore, LockOptions theOptions, SInt32 initialCount, SInt32 maximumCount);
  132.  
  133. extern OSStatus DeleteCountingSemaphore(CountingSemaphore *theCountingSemaphore);
  134.  
  135. extern OSStatus WaitForCountingSemaphore(CountingSemaphore *theCountingSemaphore);
  136.  
  137. extern OSStatus SignalCountingSemaphore(CountingSemaphore *theCountingSemaphore);
  138.  
  139. extern SInt32 GetCountingSemaphoreCount(CountingSemaphore *theCountingSemaphore);
  140.  
  141. extern SInt32 GetCountingSemaphoreMaxCount(CountingSemaphore *theCountingSemaphore);
  142.  
  143. extern ItemCount GetCountingSemaphoreWaiterCount(CountingSemaphore *theCountingSemaphore);
  144.  
  145. /*
  146.  Interrupt enabling and disabling.  ** MAY ONLY BE CALLED FROM PRIVILEGED CODE!!! **
  147.  Use very sparingly.
  148. */
  149. extern InterruptState DisableInterrupts(void );
  150.  
  151. extern void RestoreInterrupts(InterruptState theState);
  152.  
  153. /*
  154.  Atomic operations on 8-, 16-, and 32-bit entities.
  155.  ** OPERATIONS THAT CROSS WORD (32-BIT) BOUNDARIES WILL FAIL!!! **
  156. */
  157. extern Boolean CompareAndSwapAligned(UInt32 oldValue, UInt32 newValue, UInt32 *theValue);
  158.  
  159. /* Note: TestAndSet uses PPC bit ordering, zero is the high bit, and theBit ranges from 0 - FFFFFFFF.*/
  160. extern Boolean TestAndSet(UInt32 theBit, UInt8 *startAddress);
  161.  
  162. extern SInt8 IncrementAtomic8(SInt8 *value);
  163.  
  164. extern SInt8 DecrementAtomic8(SInt8 *value);
  165.  
  166. extern SInt8 AddAtomic8(SInt32 amount, SInt8 *value);
  167.  
  168. extern UInt8 BitAndAtomic8(UInt32 mask, UInt8 *value);
  169.  
  170. extern UInt8 BitOrAtomic8(UInt32 mask, UInt8 *value);
  171.  
  172. extern UInt8 BitXorAtomic8(UInt32 mask, UInt8 *value);
  173.  
  174. extern SInt16 IncrementAtomic16Aligned(SInt16 *theValue);
  175.  
  176. extern SInt16 DecrementAtomic16Aligned(SInt16 *theValue);
  177.  
  178. extern SInt16 AddAtomic16Aligned(SInt32 theAmount, SInt16 *theValue);
  179.  
  180. extern UInt16 BitAndAtomic16Aligned(UInt32 theMask, UInt16 *theValue);
  181.  
  182. extern UInt16 BitOrAtomic16Aligned(UInt32 theMask, UInt16 *theValue);
  183.  
  184. extern UInt16 BitXorAtomic16Aligned(UInt32 theMask, UInt16 *theValue);
  185.  
  186. extern SInt32 IncrementAtomicAligned(SInt32 *theValue);
  187.  
  188. extern SInt32 DecrementAtomicAligned(SInt32 *theValue);
  189.  
  190. extern SInt32 AddAtomicAligned(SInt32 theAmount, SInt32 *theValue);
  191.  
  192. extern UInt32 BitAndAtomicAligned(UInt32 theMask, UInt32 *theValue);
  193.  
  194. extern UInt32 BitOrAtomicAligned(UInt32 theMask, UInt32 *theValue);
  195.  
  196. extern UInt32 BitXorAtomicAligned(UInt32 theMask, UInt32 *theValue);
  197.  
  198. /* Atomic primitives for singly linked list manipulation.*/
  199. extern void PushListElementAtomic(void *theListHead, void *theListElement, UInt32 theLinkOffset);
  200.  
  201. extern void *PopListElementAtomic(void *theListHead, UInt32 theLinkOffset);
  202.  
  203. #endif
  204.  
  205. #pragma options align=reset
  206. #endif /* PRAGMA_ALIGN_SUPPORTED */
  207.  
  208. #if PRAGMA_IMPORT_SUPPORTED
  209. #pragma import off
  210. #endif
  211.  
  212. #ifdef __cplusplus
  213. }
  214. #endif
  215.  
  216. #endif /* __SYNCHRONIZATION__ */
  217.  
  218.